package leetcode.editor.cn.q1xx

class Q179 {
    fun largestNumber(nums: IntArray): String {
        val builder = StringBuilder()
        nums.sortedWith(Comparator { x, y ->
            val sx = "$x$y"
            val sy = "$y$x"
            return@Comparator sy.compareTo(sx)
        }).forEach {
            if (!builder.isEmpty() || it != 0) {
                builder.append(it)
            }
        }
        if (builder.isEmpty())
            builder.append(0)
        return builder.toString()
    }
}